Skip to content

Conversation

tbagrel1
Copy link

@tbagrel1 tbagrel1 commented Sep 2, 2025

Closes github.com/tweag/cardano-peras/issues/85.

@tbagrel1 tbagrel1 linked an issue Sep 2, 2025 that may be closed by this pull request
@tbagrel1 tbagrel1 changed the title [WIP] Add NodeToNode Codec for PerasCertDiffusion Add NodeToNode Codec for PerasCertDiffusion Sep 3, 2025
@tbagrel1
Copy link
Author

tbagrel1 commented Sep 3, 2025

Given what we said in the weekly meeting today, I think this should be enough to complete ticket tweag/cardano-peras#85. Let me know if I missed something :)

Copy link
Contributor

@agustinmista agustinmista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small comment/question 😄

@tbagrel1 tbagrel1 requested a review from amesgen September 4, 2025 14:32
@amesgen amesgen added the Peras label Sep 4, 2025
Copy link
Member

@amesgen amesgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only very minor comments

@@ -66,3 +70,14 @@ instance StandardHash blk => BlockSupportsPeras blk where

perasCertRound = pcCertRound
perasCertBoostedBlock = pcCertBoostedBlock

instance Serialise (HeaderHash blk) => Serialise (PerasCert blk) where
encode PerasCert{..} =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: The style guide asks us to not use RecordWildCards. (I personally like them though 😅 And there are still lots of usages left from before this rule existed.)

decodeListLenOf 2
pcCertRound <- decode
pcCertBoostedBlock <- decode
pure $ PerasCert pcCertRound pcCertBoostedBlock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think it is somewhat preferable to use NamedFieldPuns here, to make sure that we are passing the arguments to the constructor in the right order (ie in its current form, the code would also compile if we wrote pure $ PerasCert pcCertBoostedBlock pcCertRound).

@@ -173,6 +183,30 @@ deriving newtype instance
SerialiseNodeToNode blk (GenTxId blk) =>
SerialiseNodeToNode blk (WrapGenTxId blk)

-- TODO: move these orphan instances elsewhere
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if they are defined here, they actually aren't orphan instances (note that the orphan warning isn't disabled in this file), so this can be removed.

@@ -173,6 +183,30 @@ deriving newtype instance
SerialiseNodeToNode blk (GenTxId blk) =>
SerialiseNodeToNode blk (WrapGenTxId blk)

-- TODO: move these orphan instances elsewhere
instance ConvertRawHash blk => SerialiseNodeToNode blk (Point blk) where
encodeNodeToNode _ccfg _version = encodePoint $ encodeRawHash (Proxy :: Proxy blk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
encodeNodeToNode _ccfg _version = encodePoint $ encodeRawHash (Proxy :: Proxy blk)
encodeNodeToNode _ccfg _version = encodePoint $ encodeRawHash (Proxy @blk)

Also search for "Proxy" in the style guide

Comment on lines +198 to +208
instance ConvertRawHash blk => SerialiseNodeToNode blk (PerasCert blk) where
-- Consistent with the 'Serialise' instance for 'PerasCert' defined in Ouroboros.Consensus.Block.SupportsPeras
encodeNodeToNode ccfg version PerasCert{..} =
encodeListLen 2
<> encodeNodeToNode ccfg version pcCertRound
<> encodeNodeToNode ccfg version pcCertBoostedBlock
decodeNodeToNode ccfg version = do
decodeListLenOf 2
pcCertRound <- decodeNodeToNode ccfg version
pcCertBoostedBlock <- decodeNodeToNode ccfg version
pure $ PerasCert pcCertRound pcCertBoostedBlock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also just defer to encode/decode here as you did for PerasRoundNo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define serialization for certificates
3 participants